/**
 * This is the HaHaTester class. This class will take ask for a number of disks, the move count
 * in which to display the stack status, and also to control the disk movement
 * from stack to stack.  
 *
 */
import java.util.Scanner;

public class HaHaTester
{
	private LinkedStack one, two, three;
	private int moveCounter, numDisks, moveVar;
	private Scanner keyboard = new Scanner(System.in);
	
	public static void main(String[] args)
	{
		System.out.println("Welcome to the Towers of Haha!!!");
		HaHaTester haha = new HaHaTester();
		haha.setup();
		System.out.println("The starting towers look like:");
		haha.stackStatus();
		
		haha.moveDisks();
		
		System.out.println("The ending towers look like:");
		haha.stackStatus();
	}

  /**
	* This method sets up the three towers, the first
	* one with n disks.
	*
	* @exception	none - No exceptions thrown
	* @see			"No burrowed code"
	*/
	public void setup()
	{
		one = new LinkedStack();
		three = new LinkedStack();
		two = new LinkedStack();
		this.moveCounter = 0;
		
		System.out.println("How many Disks would you like to use?");
		
		numDisks = numberGrabber();
		for(int i = numDisks; i > 0; i--)
		{
			String color = "";
			
			if(i%2 == 0)
				color += "Yellow";
			else
				color += "Red";
			
			one.push(new Disk(i, color));
		}
		
		System.out.println("After how many moves would you like a status printout ?");
		moveVar = numberGrabber();
	}//End of setup()
	
  /**
	* This method calls a LinkedStack toString and 
	* configs the output.  Also displays total moves.
	*
	* @exception	none - No exceptions thrown
	* @see			"No burrowed code"
	*/
	public void stackStatus()
	{
		System.out.println("Tower one looks like:\n"+one);
		System.out.println("Tower two looks like:\n"+two);
		System.out.println("Tower three looks like:\n"+three);
		System.out.println();
		System.out.println("The total number of moves that have occured is "+moveCounter);
		System.out.println();
	}//End of stackStatus()
	
  /**
	* This method moves the disks between stacks.
	*
	* @exception	none - No exceptions thrown
	* @see			"No burrowed code"
	*/
	public void moveDisks()
	{
		for(int i = numDisks; i > 1; i--)
		{
			three.push(one.pop());
			moveCounter++;
			moveCheck();
		}
		
		two.push(one.pop());
		moveCounter++;
		moveCheck();
		
		for (int j=0; j<numDisks-1;j++)
		{
			two.push(three.pop());
			moveCounter++;
			moveCheck();
		}
	}//End of moveDisks()
	
  /**
	* This method checks if the current move is one that
	* the user wanted stack status on.
	*
	* @exception	none - No exceptions thrown
	* @see			"No burrowed code"
	*/
	private void moveCheck()
	{
		if(moveCounter%moveVar == 0)
			stackStatus();
	}//End of moveCheck()
	
  /**
	* This method looks at the input and checks to see 
	* if it is an int.
	*
	* @return		int - The users integer input
	* @exception	none - No exceptions thrown
	* @see			"No burrowed code"
	*/
	private int numberGrabber()
	{
		int temp;
		while (!keyboard.hasNextInt())//Check for non int entry
		{
			keyboard.nextLine();//Clear the bad entry
			System.out.println("You did not enter an integer.");
			System.out.print("Please enter an integer: ");
			
		}
		temp = keyboard.nextInt();
		keyboard.nextLine();//Clear the return from the Scanner
		return temp;
	}//End of numberGrabber()


}